package com.sh.data.engine.web.webapi.controller.api;

import com.sh.data.engine.application.model.request.api.DataApiMyApplyRequest;
import com.sh.data.engine.application.service.api.DataApiMyApplyApplicationService;
import com.sh.data.engine.domain.annotation.LogExecution;
import com.sh.data.engine.domain.annotation.userlog.Business;
import com.sh.data.engine.domain.annotation.userlog.EngineOperation;
import com.sh.data.engine.domain.api.model.domain.DataApiMyApplyDomain;
import com.sh.data.engine.domain.api.service.DataApiAuthService;
import com.sh.data.engine.domain.api.service.DataApiMyApplyService;
import com.sh.data.engine.domain.base.model.PageResult;
import com.sh.data.engine.web.webapi.controller.base.response.RestResponseEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author : fuchen
 * @date : 2022/1/20 17:05
 */
@RestController
@RequestMapping("/dataApiMyApply")
@Tag(name = "数据服务-我的申请", description = "数据服务-我的申请")
@Slf4j
public class DataApiMyApplyController {

    @Autowired
    private DataApiMyApplyService dataApiMyApplyService;

    @Autowired
    private DataApiAuthService dataApiAuthService;

    @Autowired
    private DataApiMyApplyApplicationService dataApiMyApplyApplicationService;


    @GetMapping("/getMyApplyApiPage")
    @Operation(summary = "我的申请")
//    @AuthorityAnnotation(menuId = MenuEnumNew.WDSQ, readWriteStatus = 0)
    public RestResponseEntity<PageResult<DataApiMyApplyDomain>> getMyApplyApiPage(
        @Valid DataApiMyApplyRequest dataApiApproveRequest) {
        var result = dataApiMyApplyApplicationService.getMyApplyApiPage(dataApiApproveRequest);
        return RestResponseEntity.success(result);
    }

    @Operation(summary = "申请使用")
    @PostMapping("/applyApiById")
    @LogExecution(operation = EngineOperation.APPLYFOR, business = Business.数据服务)
//    @Log(
//        business = Business.数据服务,
//        operation = Operation.APPLYFOR)
//    @AuthorityAnnotation(menuId = MenuEnumNew.WDSQ, readWriteStatus = 1)
    public RestResponseEntity<Boolean> applyApiById(Long id) {
        var result = dataApiMyApplyApplicationService.applyApiById(id);
        return RestResponseEntity.success(result);
    }

    @Operation(summary = "撤回申请")
    @PostMapping("/cancelApiApproveById")
    @LogExecution(operation = EngineOperation.CANCELAPPLYFOR, business = Business.数据服务)
//    @Log(
//        business = Business.数据服务,
//        operation = Operation.CANCELAPPLYFOR)
//    @AuthorityAnnotation(menuId = MenuEnumNew.WDSQ, readWriteStatus = 1)
    public RestResponseEntity<Boolean> cancelApiApproveById(Long id) {
        var result = dataApiMyApplyApplicationService.cancelApiApproveById(id);
        return RestResponseEntity.success(result);
    }

    @Operation(summary = "删除申请")
    @PostMapping("/deleteApproveById")
    @LogExecution(operation = EngineOperation.DELETEAPPLYFOR, business = Business.数据服务)
//    @Log(
//        business = Business.数据服务,
//        operation = Operation.DELETEAPPLYFOR)
//    @AuthorityAnnotation(menuId = MenuEnumNew.WDSQ, readWriteStatus = 1)
    public RestResponseEntity<Boolean> deleteApproveById(Long id) {
        var result = dataApiMyApplyApplicationService.deleteApproveById(id);
        return RestResponseEntity.success(result);
    }
}
